package com.excel.service;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.entity.Recharge;
import com.excel.utils.ExcelUtil;
import com.interfaces.RechargeDao;
import com.recharge.entity.JsonRecharge;
import com.recharge.srevice.RechargeService;
import com.report.service.RechargeReportService;
import com.utils.JsonResult;

/**
 * @Title: ExcelRechargeReportService.java
 * @Package com.excel.service
 * @author 孙梦楠
 * @date 2017年9月20日 下午3:33:23
 * @version V1.0.0
 */
@Service
public class ExcelRechargeReportService {

	@Autowired
	private RechargeDao rechargedao;

	@Autowired
	private RechargeReportService rechargereportservice;

	// 展示操作员购电报表
	@Transactional
	public JsonResult<List<JsonRecharge>> rechargereport(String issuetime1, String issuetime2, String opecode,
			String languagecookie) throws Exception {

		String direction = "购电";
		List<Recharge> recharges = rechargedao.listRechargeReport(issuetime1, issuetime2, opecode, direction);

		// 总计报表函数
		List<JsonRecharge> rechargehistories = rechargereportservice.totelReport(languagecookie, recharges);

		// 导出函数

		Map<String, String> map = new HashMap<String, String>();
		map.put("date", getDate());
		ExcelUtil.getInstance().exportObj2ExcelByTemplate(map, "web-info-template.xls", new FileOutputStream("E:/Java/out.xls"), rechargehistories, JsonRecharge.class, true);

		return new JsonResult<List<JsonRecharge>>(661, "购电报表_个人", rechargehistories);
	}

	private String getDate() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
		return sdf.format(new Date());
	}

}
